import { createWebHistory, createRouter ,createWebHashHistory} from "vue-router";
import Layout from "@/layout";

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue'),
      },
    ],
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("@/views/error/404"),
    // redirect: import.meta.env.VITE_APP_ENV == 'production' ? './index' : '',
    hidden: true,
  },
  {
    path: "/401",
    component: () => import("@/views/error/401"),
    hidden: true,
  },
  {
    path: "",
    component: Layout,
    redirect: "/index",
    children: [
      {
        path: "/index",
        component: () => import("@/views/index"),
        name: "Index",
        meta: {
          title: "首页",
          titleEn: "Home Page",
          icon: "dashboard",
          affix: true,
        },
      },
    ],
  }, 
    {
      path: "/devops",
      component: Layout,
      redirect: "/devops/build",
      name: "Devops",
      children: [
        {
          path: "gen",
          name: "Gen",
          component: () => import("@/views/tool/gen/index.vue"),
          meta: {
            icon: "code",
            title: "表单生成",
            titleEn: "Tool: Table Generate",
            linkTarget: "_self",
          },
        },
      ],
    },
];

export const dynamicRoutes = [
   
];

const router = createRouter({
  
  history: createWebHistory(), //createWebHashHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

// 应用路由守卫
// router.beforeEach(checkNavigationGuard)

export default router;
